package com.ruoyi.web.controller.shortplay;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shortplay.domain.VideoCover;
import com.ruoyi.shortplay.service.IVideoCoverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * AI封面Controller
 *
 * @author ruoyi
 * @date 2025-11-18
 */
@RestController
@RequestMapping("/shortplay/cover")
public class VideoCoverController extends BaseController {
    @Autowired
    private IVideoCoverService videoCoverService;

    /**
     * 查询AI封面列表
     */
    @GetMapping("/list")
    public TableDataInfo list(VideoCover videoCover) {
        startPage();
        List<VideoCover> list = videoCoverService.selectVideoCoverList(videoCover);
        return getDataTable(list);
    }

    /**
     * 导出AI封面列表
     */
    @Log(title = "AI封面", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VideoCover videoCover) {
        List<VideoCover> list = videoCoverService.selectVideoCoverList(videoCover);
        ExcelUtil<VideoCover> util = new ExcelUtil<VideoCover>(VideoCover.class);
        util.exportExcel(response, list, "AI封面数据");
    }

    /**
     * 获取AI封面详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(videoCoverService.selectVideoCoverById(id));
    }

    /**
     * 新增AI封面
     */
    @Log(title = "AI封面", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VideoCover videoCover) {
        return toAjax(videoCoverService.insertVideoCover(videoCover));
    }

    /**
     * 修改AI封面
     */
    @Log(title = "AI封面", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VideoCover videoCover) {
        return toAjax(videoCoverService.updateVideoCover(videoCover));
    }

    /**
     * 删除AI封面
     */
    @Log(title = "AI封面", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(videoCoverService.deleteVideoCoverByIds(ids));
    }
}
